package com.bdqn.day0106.mybatis.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Date;
import java.util.Calendar;


/**
 * @Author:Corday
 * @Date:2022/01/06/10:52 孩子实体类
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Child {
    private Integer cid;
    private String name;
    private String gendar;
    private Date birth;
    //    母亲实体中的id号
    private Integer mid;
    //保存年龄
    private Integer age;

    //    计算出年龄
    public Integer getAge() {
        Calendar cd = Calendar.getInstance();
//     拿到当前的年份(请计算出精确年龄,sql语句，java代码)
        int nowYear = cd.get(Calendar.YEAR);
//      传入出生日期对象,cd对象的内容已更新 ,获取出生日期中的年份
        cd.setTime(this.birth);
        int birthYear = cd.get(Calendar.YEAR);
        return nowYear-birthYear;
    }


}

